<!--  -->
<template>
    <div>

        <van-form @submit="onSubmit">

            <!-- 头 -->
            <div class="font15 mt10 pl10">
                <span class="titletext">{{ nFromdata.title }}</span>
                <div class="graytext mt10 font13">
                    <span>工单编号：</span>
                    <span class="titletext">{{ nFromdata.pmInsId }}</span>
                </div>
            </div>


            <section-header :sectionTitle="'二次谈判'" />
            <div>
                <van-field readonly required name="pickActivityName" :value="fromdata.pickActivityName" label="甄选项目名称:"
                    label-width="7em" />
                <van-field readonly required name="pickApplyCode" :value="fromdata.pickApplyCode" label="甄选项目编码:"
                    label-width="7em" />
                <van-field readonly required name="removeTaxMoney" :value="fromdata.removeTaxMoney" label="不含税金额（万元）:"
                    label-width="10em" />
                <van-field readonly required name="containTaxMoney" :value="fromdata.containTaxMoney" label="含税金额（万元）:"
                    label-width="9em" />
                <van-field readonly required name="proposedContractType" :value="fromdata.proposedContractType" label="拟签署合同类型:"
                    label-width="8em" />
                <van-field readonly required name="negotiationResultState" :value="fromdata.negotiationResultState"
                    label="谈判结果是否应用:" label-width="9em" />
                <van-field v-if="fromdata.negotiationResultState == '否'" readonly required name="negotiationHandleMode"
                    :value="fromdata.negotiationHandleMode" label="处理方式:" label-width="5em" />
            </div>
            

            <section-header :sectionTitle="'合作伙伴信息'" />
            <el-table :data="fromdata.pickPartnerAnswerList" :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }" border style="width: 100%">
                <el-table-column prop="partnerName" label="合作伙伴名称" width="140" />
                <el-table-column prop="partnerCode" label="合作伙伴编码" width="140" />
                <el-table-column prop="twoNegotiationTime" label="二次谈判时间" width="140" />
                <el-table-column prop="twoNegotiationYear" label="二次谈判使用年度" width="140" />
                <el-table-column prop="twoRemoveTaxMoney" label="二次谈判不含税金额" width="150" />
                <el-table-column prop="twoRemoveTaxAckMoney" label="二次谈判确认不含税金额" width="180" />
                <el-table-column prop="twoContainTaxMoney" label="二次谈判含税金额" width="140" />
                <el-table-column prop="twoContainTaxAckMoney" label="二次谈判确认含税金额" width="170" />
                <el-table-column prop="twoNegotiationTaxRate" label="二次谈判确认税率" width="140" />
            </el-table>


            <section-header :sectionTitle="'附件'" />
            <div>
                <van-field readonly required label="二次谈判过程文件:" label-width="9em" />
                <div v-for="(fileitem) in fromdata.twoNegotiateList" :key="fileitem.id" style="margin-left:20px">
                    <div readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                    </div>
                </div>

                <van-field readonly required label="二次谈判结果文件:" label-width="9em" />
                <div v-for="(fileitem) in fromdata.twoNegotiateResultList" :key="fileitem.id" style="margin-left:20px">
                    <div readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                    </div>
                </div>

                <!-- 市公司流程 请部门副经理审批环节及后续环节 -->
                <!-- 请部门副经理审批环节 可编辑 -->
                <div v-if="hasApprovalComments">
                    <van-field readonly required name="approvalComments" :value="fromdata.approvalComments" label="审批意见:"
                        label-width="5em" :right-icon="canEditRejectReason ? 'arrow' : ''"
                        @click="approvalCommentsShow = canEditRejectReason" :rules="[{ required: true, message: '请输入审批意见' }]" />
                    <van-popup v-model="approvalCommentsShow" position="bottom" get-container="body">
                        <van-picker show-toolbar value-key="value" :columns="approvalCommentsColumns"
                            @confirm="approvalCommentsOnConfirm" @cancel="approvalCommentsShow = false">
                        </van-picker>
                    </van-popup>


                    <van-field v-if="fromdata.approvalComments == '不同意'" v-model="fromdata.rejectReason" :readonly="!canEditRejectReason" required autosize type="textarea" rows="1"
                        name="rejectReason" label="驳回原因:" label-width="5em" :rules="[{ required: true, message: '请输入驳回原因' }]"/>
                </div>
            </div>


            <!-- 跳转意见 -->
            <div class="left_botton">
                <button block type="button" @click="tomsg()" style="color:#60a9ec; display: inline-block;width:100%;border: 0px solid #60a9ec;border-radius: 15px 0px 0px 15px;
            padding:10px 10px 10px 15px;font-size:13px">意见</button>
            </div>

            
            <!-- 流转下一步 -->
            <div v-if="todotype||toRead" class="footer">
                <van-button block type="info" native-type="submit" :disabled="!canToNext"
                    style="display: inline-block; width: 100%; border: 0px solid #60a9ec">{{ buttonTitle }}</van-button>
            </div>
        </van-form>


        <!-- 当前办理人 -->
        <section-header v-if="showHistory" :sectionTitle="'当前办理人:'" />
        <div v-if="showHistory" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>


        <!-- 审批意见 -->
        <section-header id="opinion" :sectionTitle="'审批意见:'" />
        <opinion-item :approveList="approveList" />
    </div>
</template>


<script>

import { mapGetters } from "vuex";
import { Notify, Toast } from "vant";
import { openFileUrl } from "@/store/openFile";
import util from "@/assets/js/public";
import {
    getZXGSSPFormDetail,
    byPmInsIdFindTwoNegotiation,
    getWfOptMags,
    getWfLinkTracks,
} from "@/api/dictapi";
import SectionHeader from '../sztdzj/sztdzjDetail/section-header.vue';
import OpinionItem from '../sztdzj/sztdzjDetail/opinion-item.vue';


export default {
    data() {
        return {
            fromdata: {},
            nFromdata: {},

            params: this.$route.query,
            todotype: false,
            approveList: [],

            showHistory: false,
            historydata: {},
            toRead: false,
            approvalCommentsShow: false,
            approvalCommentsColumns: [{ label: '同意', value: '同意' },
            { label: '不同意', value: '不同意' }],


            buttonTitle: '流转下一步',
            canToNext: true,
        };
    },

    computed: {

        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),

        /// 审批意见
        hasApprovalComments() {

            var location = this.params.location;
            if ((location == "dict.startToDeputyManager" && !this.showHistory)
                || (location == "dict.startToManager" && !this.showHistory)
                || location == "dict.ManagerToPromoter"
                || (location == "dict.startToBranchDeputyManager" && !this.showHistory)
                || location == "dict.startToBranchManager"
                || location == "dict.ManagerToBranchPromoter") {

                return true;
            }
        },

        /// 审批意见、驳回原因 可编辑
        canEditRejectReason() {

            if (this.hasApprovalComments) {

                var location = this.params.location;
                if ((location == "dict.startToBranchDeputyManager" && !this.showHistory)
                    || (location == "dict.startToDeputyManager" && !this.showHistory)) {
                    return true;
                }
            }
        }
    },

    //生命周期--创建完成
    created() {
        if(this.params.pmInsType==null&&this.params.processType!=null) {
          this.params.pmInsType = this.params.processType
        }
        if (this.params.todoType == "1") {
            this.todotype = true;
        } else if (this.params.todoType == "2") {
            this.showHistory = true;
        }else if (this.params.todoType == "3") {
            this.toRead = true;
        }

        if (this.params.location == 'dict.start') {
            this.canToNext = false;
            this.buttonTitle = '暂不支持该环节,请至PC端办理';
        }

        this.getdetail();
    },

    //生命周期--挂载完成
    components: {
        SectionHeader,
        OpinionItem

    },

    //生命周期--挂载完成
    mounted() { },

    //方法调用
    methods: {

        tomsg() {
            document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
        },

        openFileUrlfun(value) {
            this.$router.push({
                name: "fileview",
                query: {
                    openFileUrl: openFileUrl(value),
                },
            });
        },

        approvalCommentsOnConfirm(value) {

            this.approvalCommentsShow = false;
            this.fromdata.approvalComments = value.value;
        },

        getdetail() {
            Toast.loading({ message: "加载中", forbidClick: false });
            getZXGSSPFormDetail(
                Object.assign(this.params, { userName: this.user.userName })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();

                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.nFromdata = result.data.data;
                }
            })

            byPmInsIdFindTwoNegotiation(
                Object.assign(this.params, { userName: this.user.userName })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.fromdata = result.data.data;
                }
            })

            getWfOptMags(Object.assign(this.params), {
                userName: this.user.userName,
            }).then((result) => {
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }
                this.approveList = result.data.data.reverse();
            })

            if (this.showHistory) {

                getWfLinkTracks(Object.assign(this.params), {
                    userName: this.user.userName,
                }).then((result) => {
                    Toast.clear();
                    if (!result.data) {
                        Notify(result.message);
                        return;
                    }
                    if (result.data.data) {
                        //数据过滤，并生成新的数组
                        this.historydata = result.data.data.filter(
                            (item) => item.CURRENTSTATE == 10
                        )[0];
                        if (this.historydata) {
                            if (this.historydata.MANAGER) {
                                this.showHistory = true;
                            } else {
                                this.showHistory = false;
                            }
                        } else {
                            this.showHistory = false;
                        }
                    } else {
                        this.showHistory = false;
                    }
                })
            }
        },


        onSubmit() {

            var fromdataTwo = Object.assign(this.fromdata, {partnerAnswerList :this.fromdata.pickPartnerAnswerList});
            delete fromdataTwo.pickPartnerAnswerList;

            var formSendData = { "htmlParamMap": {} };
            formSendData.htmlParamMap = fromdataTwo;
            formSendData.id = this.nFromdata.id;
            formSendData.pmInsId = this.nFromdata.pmInsId;
            formSendData.processType = this.params.pmInsType
            formSendData.workItemId = this.params.workItemId;

            var params1 = {
                kv: {
                    currentUserCode: util.encrypt(this.params.userName),
                    source: 'MOBILE',
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    processType: this.params.pmInsType,
                },
            };

            var params2 = {
                kv: {
                    "currentUserCode": util.encrypt(this.params.userName),
                    "source": 'MOBILE',
                    "location": this.params.location,
                    "processInstId": this.params.processInstId,
                    'processType': this.params.pmInsType,
                    'receiptCode': this.params.processInstId
                },
            };

            var params3 = {
                kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.params.userName),
                    "workItemId": this.params.todoType==3?"":this.params.workItemId,
                    "processInstId": this.params.processInstId,
                    "location": this.params.location,
                    "notificationId":this.params.todoType==3?this.params.wfnid:"",
                    'processType': this.params.pmInsType,
                },
            };
            localStorage.setItem('submitPageParam', JSON.stringify({
                    getDecisionsUrl: 'decisionAndUser$api$getDecisions',
                    getUserUrl: 'decisionAndUser$api$getOrgAndUser',
                    tosubmintUrl: 'applicationFormEnhance$api$startSubmitProcess',

                    getDecisionsParams: params1,
                    getUserParams: params2,
                    tosubmintParams: params3,
                    formData: formSendData,
                    fromMoa:this.params.fromMoa,
                    type:this.params.todoType==3?"toRead":"toDo"
                }));
            this.$router.push({
                name: "srqrsubmit"
            });
        },

    },
};
</script>

<style  scoped>
/* @import url();*/
</style>